using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using System.Security.Permissions;
using System.Security.Principal;

namespace InfiniTec.Security
{
    class UserToken : SafeHandleZeroOrMinusOneIsInvalid 
    {
        [SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
        private UserToken()
            : base(true)
        {
        }

        [SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
        protected override bool ReleaseHandle()
        {
            return NativeMethods.CloseHandle(handle);
        }


        internal WindowsIdentity GetWindowsIdentity()
        {
            return new WindowsIdentity(handle);
        }
    }
}
